package com.kfm.hotel.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "R", description = "统一返回结果")
public class R {

    @ApiModelProperty(value = "code, 状态码. 200 成功, 500 失败")
    private Integer code;

    @ApiModelProperty(value = "msg, 消息。成功时为“操作成功”，失败时为具体的错误信息")
    private String msg;

    @ApiModelProperty(value = "data, 数据。成功时为具体的数据，失败时为null")
    private Object data;

    public static R ok(String msg, Object data){
        return new R(200, msg, data);
    }

    public static R ok(String msg){
        return new R(200, msg, null);
    }
    public static R ok(Object data){
        return new R(200, "操作成功", data);
    }

    public static R fail(String msg){
        return new R(500, msg, null);
    }
}
